using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;

namespace UserManagementService.Permissions;

/// <summary>
/// 用户权限服务接口
/// </summary>
public interface IUserPermissionService
{
    /// <summary>
    /// 获取用户所有权限
    /// </summary>
    Task<List<string>> GetUserPermissionsAsync(Guid userId, CancellationToken cancellationToken = default);

    /// <summary>
    /// 检查用户是否有指定权限
    /// </summary>
    Task<bool> HasPermissionAsync(Guid userId, string permissionName, CancellationToken cancellationToken = default);

    /// <summary>
    /// 检查用户是否有任一权限
    /// </summary>
    Task<bool> HasAnyPermissionAsync(Guid userId, params string[] permissionNames);

    /// <summary>
    /// 检查用户是否有所有权限
    /// </summary>
    Task<bool> HasAllPermissionsAsync(Guid userId, params string[] permissionNames);

    /// <summary>
    /// 授予权限给用户
    /// </summary>
    Task GrantPermissionAsync(Guid userId, string permissionName, string? grantedBy = null, CancellationToken cancellationToken = default);

    /// <summary>
    /// 批量授予权限给用户
    /// </summary>
    Task GrantPermissionsAsync(Guid userId, List<string> permissionNames, string? grantedBy = null, CancellationToken cancellationToken = default);

    /// <summary>
    /// 撤销用户权限
    /// </summary>
    Task RevokePermissionAsync(Guid userId, string permissionName, string? revokedBy = null, CancellationToken cancellationToken = default);

    /// <summary>
    /// 批量撤销用户权限
    /// </summary>
    Task RevokePermissionsAsync(Guid userId, List<string> permissionNames, string? revokedBy = null, CancellationToken cancellationToken = default);

    /// <summary>
    /// 获取用户权限变更历史
    /// </summary>
    Task<List<UserPermissionHistoryDto>> GetPermissionHistoryAsync(Guid userId, DateTime? startTime = null, DateTime? endTime = null, CancellationToken cancellationToken = default);

    /// <summary>
    /// 获取权限范围内的用户列表
    /// </summary>
    Task<List<Guid>> GetUsersWithPermissionAsync(string permissionName, CancellationToken cancellationToken = default);

    /// <summary>
    /// 获取用户角色权限
    /// </summary>
    Task<List<string>> GetUserRolePermissionsAsync(Guid userId, CancellationToken cancellationToken = default);

    /// <summary>
    /// 获取用户直接权限
    /// </summary>
    Task<List<string>> GetUserDirectPermissionsAsync(Guid userId, CancellationToken cancellationToken = default);

    /// <summary>
    /// 刷新用户权限缓存
    /// </summary>
    Task RefreshUserPermissionCacheAsync(Guid userId, CancellationToken cancellationToken = default);
}